Skip to content

Conversation

@Guilherme1Rocha
Copy link

@Guilherme1Rocha Guilherme1Rocha commented Dec 9, 2025

Support executing client-side Git hooks via ClientHookCommands

This PR introduces a new ClientHookCommands module in git_commands to handle execution of Git client hooks in a consistent and Git-faithful manner. Hooks such as prepare-commit-msg are executed automatically when appropriate, and the behavior for missing or non-executable hooks mirrors Git’s defaults.

  • New ClientHookCommands module

    • Encapsulates hook path resolution, command execution, and error handling.
    • Honors core.hooksPath when configured, falling back to the repository’s .git/hooks directory.
  • Integration with commit flow

    • prepare-commit-msg hook is invoked when no commit prefix is generated from user configuration.
    • Missing or non-executable hooks are silently ignored, allowing commits to proceed normally.
    • Executable hooks that fail (non-zero exit) are surfaced to the caller.

Fixes #4995

Please check if the PR fulfills these requirements

  • Cheatsheets are up-to-date (run go generate ./...)
  • Code has been formatted (see here)
  • Tests have been added/updated (see here for the integration test guide)
  • Text is internationalised (see here)
  • If a new UserConfig entry was added, make sure it can be hot-reloaded (see here)
  • Docs have been updated if necessary
  • You've read through your own file changes for silly mistakes etc

@Guilherme1Rocha Guilherme1Rocha force-pushed the feature/prepare-commit-msg-git-hook-support branch from 8a9c3ee to ba498d1 Compare December 25, 2025 21:56
@Guilherme1Rocha Guilherme1Rocha force-pushed the feature/prepare-commit-msg-git-hook-support branch from ba498d1 to d964c2f Compare January 25, 2026 22:06
@Guilherme1Rocha Guilherme1Rocha changed the title Add ClientHookCommands to run Git client hooks and default support for prepare-commit-msg hook Add support for client-side Git hooks and prepare-commit-msg hook Jan 25, 2026
This change enables lazygit to execute standard client-side Git hooks
when they are present in the repository's hooks directory (or a
custom directory specified via core.hooksPath).

Hooks are only executed if they exist and the command can be run. Missing
or non-executable hooks are silently ignored, allowing Git operations
to continue normally. If a hook is executable and fails (non-zero exit),
the failure is surfaced to the caller.

Unit tests cover all scenarios, including:
- hooks that run successfully,
- hooks that fail,
- non-executable hooks (simulated failure),
- and missing hooks.
When no commit message is preserved, lazygit attempts to generate a
commit prefix before opening the commit flow. User-configured commit
prefix patterns are evaluated first and applied based on the current
branch name.

If no configured prefix matches, lazygit falls back to invoking the
prepare-commit-msg hook using a temporary commit message file,
mirroring Git’s native behavior.

Fixes jesseduffield#4995
@Guilherme1Rocha Guilherme1Rocha force-pushed the feature/prepare-commit-msg-git-hook-support branch from d964c2f to d4f18c5 Compare January 26, 2026 19:21
@Guilherme1Rocha
Copy link
Author

@stefanhaller , Sorry for the ping.
Is this something you’d consider a desirable feature for lazygit? If yes, I’d love any feedback on issues or improvements to work on

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

support prepare-commit-msg Git hook

1 participant